﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Reflection;    //appedn by Dyh

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            //Page.RegisterHiddenField("__EVENTTARGET", this.Button_search.ClientID);   //实现按回车键提交表单，但未成功；

            Literal_Ads.Text = ADS.GetADsCode(3);


        if (!IsPostBack)
        {
            if (HiddenField_sortSelect.Value == "")
            {
                menu("1");
                //HiddenField_sortSelect.Value = "1";
                Validator1.Enabled = true;
                Validator1.Visible = true;

            }
        }

    }
    protected void Button_search_Click(object sender, EventArgs e)
    {
        string url = "detail.aspx?sel="+ HiddenField_sortSelect.Value +"&keyword="+TextBox_input.Text;
        Response.Redirect(url);
    }
    protected void Button_report_Click(object sender, EventArgs e)
    {
        string url = "report.aspx?sel=" + HiddenField_sortSelect.Value + "&keyword=" + TextBox_input.Text;
        Response.Redirect(url);

    }
    protected void LinkButton_1_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "1";   //电话
        menu("1");
        //validator_Select("1");
        Validator1.Enabled = true;
        Validator1.Visible = true;
    }
    protected void LinkButton_2_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "2";   //网站
        menu("2");
        //validator_Select("2");
        Validator2.Enabled = true;
        Validator2.Visible = true;

    }
    protected void LinkButton_3_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "3";   //身份证
        menu("3");
        //validator_Select("3");
        Validator3.Enabled = true;
        Validator3.Visible = true;
    }
    protected void LinkButton_4_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "4";   //银行
        menu("4");
        //validator_Select("4");
        Validator4.Enabled = true;
        Validator4.Visible = true;
    }
    protected void LinkButton_5_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "5";   //QQ号码
        menu("5");
        //validator_Select("5");
        Validator5.Enabled = true;
        Validator5.Visible = true;
    }
    protected void LinkButton_6_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "6";   //资讯
        menu("6");
        //validator_Select("6");
        Validator6.Enabled = true;
        Validator6.Visible = true;
    }
    protected void LinkButton_7_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "7";   //论坛
        menu("7");
        //validator_Select("7");
        Validator0.Enabled = true;
        Validator0.Visible = true;
    }
    protected void LinkButton_8_Click(object sender, EventArgs e)
    {
        //HiddenField_sortSelect.Value = "8";   //其它
        menu("8");
        //validator_Select("8");
        Validator0.Enabled = true;
        Validator0.Visible = true;
    }

    private void menu(string sel)
    {
        HtmlGenericControl div_a;
        HtmlTableCell td_1;
        HtmlTableCell td_2;
        LinkButton lb;
        Image img;
        string hidden_value=HiddenField_sortSelect.Value.Trim();

        if (hidden_value != "")
        {
            div_a = (HtmlGenericControl)table_Menu.FindControl("DIV_select_" + hidden_value);
            div_a.Attributes["class"] = "b";
            div_a.Attributes["onmouseover"] = "this.className=\"c\"";
            div_a.Attributes["onmouseout"] = "this.className=\"b\"";

            td_1 = (HtmlTableCell)table_Menu.FindControl("TD1_select_" + hidden_value);
            td_1.Attributes["class"] = "i";

            td_2 = (HtmlTableCell)table_Menu.FindControl("TD2_select_" + hidden_value);
            td_2.Attributes["class"] = "j";

            lb = (LinkButton)table_Menu.FindControl("LinkButton_" + hidden_value);
            lb.ForeColor = System.Drawing.Color.Black;

            img = (Image)table_Menu.FindControl("Image_" + hidden_value);
            img.ImageUrl = "";
            img.Visible = false;
        }

        
        //动态访问控件，实现相关属性的设置，设置该控件为激活状态
                div_a = (HtmlGenericControl)table_Menu.FindControl("DIV_select_" + sel);
                div_a.Attributes["class"] = "a2";
                div_a.Attributes["onmouseover"] = "";
                div_a.Attributes["onmouseout"] = "";

                td_1 = (HtmlTableCell)table_Menu.FindControl("TD1_select_" + sel);
                td_1.Attributes["class"] = "h";

                td_2 = (HtmlTableCell)table_Menu.FindControl("TD2_select_" + sel);
                td_2.Attributes["class"] = "a";

                lb = (LinkButton)table_Menu.FindControl("LinkButton_" + sel);
                lb.ForeColor = System.Drawing.Color.White;

                img = (Image)table_Menu.FindControl("Image_" + sel);
                img.ImageUrl = "App_Themes/WinXP_Silver/Images/g.gif";
                img.Visible = true;

        

                //设置当前的查询类别
                HiddenField_sortSelect.Value = sel;
        //    }
        //}

    }


    private void validator_Select(string sel)
    {
        RegularExpressionValidator _validator;
        string hidden_value = HiddenField_sortSelect.Value.Trim();
        if (hidden_value!=sel)
        {
            _validator = (RegularExpressionValidator)regular.FindControl("Validator"+sel);
            _validator.Enabled = true;
            _validator.Visible = true;

            _validator = (RegularExpressionValidator)regular.FindControl("Validator" + hidden_value);
            _validator.Enabled = false;
            _validator.Visible = false;

        }
    }


    //private void menu()
    //{
    //    HtmlGenericControl div_a;
    //    HtmlTableCell td_1;
    //    HtmlTableCell td_2;
    //    LinkButton lb;
    //    Image img;
    //    for (int i = 1; i <= 8; i++)
    //    {
    //        if (HiddenField_sortSelect.Value == i.ToString()) // i.ToString())
    //        {
    //            //动态访问控件，实现相关属性的设置
    //            div_a = (HtmlGenericControl)table_Menu.FindControl("DIV_select_" + i.ToString());
    //            div_a.Attributes["class"] = "a2";
    //            div_a.Attributes["onmouseover"] = "";
    //            div_a.Attributes["onmouseout"] = "";

    //            td_1 = (HtmlTableCell)table_Menu.FindControl("TD1_select_" + i.ToString());
    //            td_1.Attributes["class"] = "h";

    //            td_2 = (HtmlTableCell)table_Menu.FindControl("TD2_select_" + i.ToString());
    //            td_2.Attributes["class"] = "a";

    //            lb = (LinkButton)table_Menu.FindControl("LinkButton_" + i.ToString());
    //            lb.ForeColor = System.Drawing.Color.White;

    //            img = (Image)table_Menu.FindControl("Image_" + i.ToString());
    //            img.ImageUrl = "App_Themes/WinXP_Silver/Images/g.gif";
    //        }
    //        else
    //        {
    //            //动态访问控件，实现相关属性的设置
    //            div_a = (HtmlGenericControl)table_Menu.FindControl("DIV_select_" + i.ToString());
    //            div_a.Attributes["class"] = "b";
    //            div_a.Attributes["onmouseover"] = "this.className=\"c\"";
    //            div_a.Attributes["onmouseout"] = "this.className=\"b\"";

    //            td_1 = (HtmlTableCell)table_Menu.FindControl("TD1_select_" + i.ToString());
    //            td_1.Attributes["class"] = "i";

    //            td_2 = (HtmlTableCell)table_Menu.FindControl("TD2_select_" + i.ToString());
    //            td_2.Attributes["class"] = "j";

    //            lb = (LinkButton)table_Menu.FindControl("LinkButton_" + i.ToString());
    //            lb.ForeColor = System.Drawing.Color.Black;

    //            img = (Image)table_Menu.FindControl("Image_" + i.ToString());
    //            img.ImageUrl = "";

    //        }
    //    }

    //}
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string input = TextBox_input.Text.Trim();

        if (input == "")
        {
            CustomValidator1.ErrorMessage = "* 输入框不能为空，请重新输入！";
            args.IsValid = false;
        }
        else if (input == "请输入关键字...")
        {
            CustomValidator1.ErrorMessage = "* 请输入有效的查询值！";
            args.IsValid = false;
        }
    }


}
